package com.qf.agro.controller;

import com.qf.agro.common.ResultInfo;
import com.qf.agro.common.SysUserHolder;
import com.qf.agro.pojo.SysUser;
import com.qf.agro.service.SysModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 10202
 * @version V1.0
 * @Project smart-agriculture-parent
 * @Package com.qf.agro.controller
 * @Date 2023/5/22 17:49
 */
@RestController
@RequestMapping("/sys/module")
public class SysModuleController {
    private final SysModuleService  sysModuleService;

    public SysModuleController(SysModuleService sysModuleService) {
        this.sysModuleService = sysModuleService;
    }

    @GetMapping("/menu")
    public ResultInfo getMenuList(){
        SysUser sysUser = SysUserHolder.get();
        return sysModuleService.getMenuList(sysUser.getId());
    }

    @GetMapping("/list")
    public ResultInfo getModule(){

        return sysModuleService.getMenu();
    }

    @GetMapping("roleModule")
    public ResultInfo getRoleMessage(@RequestParam(value = "roleId") Long roleId){

        return sysModuleService.getRoleMessage(roleId);
    }

    @PostMapping("roleModule")
    public ResultInfo updateRoleMessage(@RequestBody Map<String,Object> roleMessageMap){
        System.out.println(roleMessageMap);
        return sysModuleService.updateRoleMessage(roleMessageMap);
    }

    @GetMapping("page")
    public ResultInfo getPageModule(@RequestParam(value = "page", defaultValue = "1") Long page,@RequestParam(value = "pageSize", defaultValue = "5") Long pageSize){


        return sysModuleService.getPageModule(page,pageSize);
    }


}
